<?php


namespace App\Http\Services\MeiTuan;


class ServiceProviderApiList
{
    protected $domain               = 'https://api-open-cater.meituan.com/';
    protected $create_by_shop_url   = 'peisong/order/createByShop'; //创建订单--门店方式
    protected $cancel_url           = 'peisong/order/cancel';       //取消订单
    protected $query_status_url     = 'peisong/order/queryStatus'; //查询订单

    protected $create_shop_url      = 'peisong/shop/create'; //创建配送门店
    protected $query_shop_url       = 'peisong/shop/query'; //查询门店信息
    protected $query_area_url       = 'peisong/shop/area/query'; //查询合作方配送范围
    protected $appAuthToken;
    public function __construct()
    {
        $this->appAuthToken = '';
        $this->create_by_shop_url   = $this->domain.$this->create_by_shop_url;
        $this->cancel_url           = $this->domain.$this->cancel_url;
        $this->query_status_url     = $this->domain.$this->query_status_url;
    }

    public function createByShop(array $payload){
        $result = SendRequest::spPostRequest($this->create_by_shop_url,$payload);
        if (!$result){
            return false;
        }
//        return $result;
        $response = $this->processResponse($result);
        return $response;
    }

    public function cancelOrder(array $payload){
        $result = SendRequest::spPostRequest($this->cancel_url,$payload);
        if (!$result){
            return false;
        }
        $response = $this->processResponse($result);
        return $response;
    }

    public function queryOrder(array $payload){
        $result = SendRequest::spPostRequest($this->query_status_url,$payload);
        if (!$result){
            return false;
        }
        $response = $this->processResponse($result);
        return $response;
    }

    public function createShop(array $payload){
        $result = SendRequest::spPostRequest($this->create_shop_url,$payload);
        if (!$result){
            return false;
        }
        $response = $this->processResponse($result);
        return $response;
    }
    public function queryShop(array $payload){
        $result = SendRequest::spPostRequest($this->query_shop_url,$payload);
        if (!$result){
            return false;
        }
        $response = $this->processResponse($result);
        return $response;
    }

    /**
     * 处理响应
     * @param $result
     * @return ResponseHandler
     */
    protected function processResponse($result): ResponseHandler
    {
        return new ResponseHandler($result);
    }
}
